package com.kaifamiao.month03.day0324;

import java.util.Scanner;

public class Score {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] nums = getScore(in);
        System.out.println("您输入的" + nums.length + " 位评委的成绩分别是：");
        for (int num : nums) {
            System.out.print(num + "\t");
        }
        System.out.println();
        System.out.println("去掉最低分和最高分之后的平均分是：" + score(nums));
    }

    /**
     * 获取评委的成绩
     * @param in 输入对象
     * @return  输入的评委成绩数组
     */
    public static int[] getScore(Scanner in){
        int[] nums = new int[6];
        for (int i = 0; i < nums.length; i++) {
            System.out.println("请输入第 " + (i + 1) + "个评委的成绩：");
            nums[i] = in.nextInt();
        }
        return nums;
    }
    /**
     * 取出最高分和最低分计算平均成绩
     * @param nums 需要计算平均成绩的数组
     * @return 平均值
     */
    public static double score(int[] nums) {
        int min = nums[0];
        int max = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > max)
                max = nums[i];
            if (nums[i] < min)
                min = nums[i];
        }
        int sum = 0;
        for (int num : nums)
            sum += num;
        return (double) (sum - min - max) / (nums.length - 2);
    }
}
